package com.msb.baseFunctionalInterface;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class SupplierTest {
    public static void main(String[] args) {
        String msg = print(()->"hello world");
        System.out.println(msg);
    }

    private static String print(Supplier<String> supplier){
        return "message: " + supplier.get();
    }

    /**
     * 集合数据的拷贝 通过返回值
     *
     * @param sources: 数据源类
     * @param target:  目标类::new(eg: UserVO::new)
     * @return 目标复制集合
     */
    public static <S, T> List<T> copyListProperties(List<S> sources, Supplier<T> target)
    {
        List<T> list = new ArrayList<>(sources.size());
        for (S source : sources)
        {
            T t = target.get();
//            BeanUtils.copyProperties(source, t);
            list.add(t);
        }
        return list;
    }

}
